﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using iTeachSoft.CoreObjects.Recording;
using iTeachSoft.Presentation.Code.Managers;

namespace iTeachSoft.Presentation.Dialogs
{
    /// <summary>
    /// Interaction logic for DialogRecordingOptions.xaml
    /// </summary>
    public partial class DialogRecordingOptions : Window
    {
        private RecordSettings mRecordingOptions = null;
        public RecordSettings RecordingOptions
        {
            get { return mRecordingOptions; }
            set
            {
                mRecordingOptions = value;
                ReflectOptions();
            }
        }

        public DialogRecordingOptions()
        {
            InitializeComponent();

            this.radioButtonMouseClick.IsChecked = true;

            this.buttonOk.Click += new RoutedEventHandler(buttonOk_Click);
            this.buttonCancel.Click += new RoutedEventHandler(buttonCancel_Click);
        }

        public DialogRecordingOptions(RecordSettings options)
            : this()
        {
            RecordingOptions = options;
        }

        private void ReflectOptions()
        {
            if (RecordingOptions == null) return;

            if (RecordingOptions.RecordType == EnumRecordType.RecordOnMouseClick)
                radioButtonMouseClick.IsChecked = true;
            else
                radioButtonKeyboardEvent.IsChecked = true;
        }

        private void UpdateReflectOptions()
        {
            if (RecordingOptions == null) mRecordingOptions = new RecordSettings();

            if (radioButtonMouseClick.IsChecked.Value)
                RecordingOptions.RecordType = EnumRecordType.RecordOnMouseClick;
            else
                RecordingOptions.RecordType = EnumRecordType.RecordOnKeyPressed;
        }

        void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        void buttonOk_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            UpdateReflectOptions();

            RecordingManager.StartRecording(RecordingOptions);
        }
    }
}
